﻿Chenxin.UI.ShowListTransfer = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/logic/ShowListTransfer.ashx',
    createSearch: function() {
        return new Chenxin.UI.ShowListTransferSearch({
            scope: this
        });
    },
    createGrid: function() {
        var _this = this;
        return new Chenxin.UI.MultiRowGrid({
            actionUrl: this.actionUrl + '?op=search',
            pageSize: 100,
            renderTo: 'transferdetail_table',
            hasCheckBox: false,
            scope: this,
            height:258,
            modelId: 'ContractId',
            id: 'transfer_trddition',
            title: '过户明细',
            cellBorder:true,
            columns: {
                ContractId: {
                    create: false,
                    head: 'id',
                    sortable: true
                },
                Finished: {
                    width: 50,
                    head: "结案",
                    canExport:false,
                    renderer:function(val,c,row){
						if(val==true){
							return '<input type="checkbox" disabled="disabled" checked="checked"/>';
						}
						return '<input type="checkbox" disabled="disabled"/>'
					}
                },
                ContractCode: {
                    width: 125,
                    head: "成交编号",
                    sortable: true
                },
                Region: {
                    width: 50,
                    head: "区县",
                    sortable: true
                },
                HouseAddress: {
                    width: 160,
                    head: "地址"
                },
                DepartName:{
					width:80,
					items:{
						VenderDepartName:{
							width:80,
							head:'上家店别'
						},
						BuyerDepartName:{
							width:80,
							head:'下家店别'
						}
					}
				},
                UserName:{
					width:80,
					items:{
						VenderUserName:{
							width:80,
							head:'上家经纪人'
						},
						BuyerUserName:{
							width:80,
							head:'下家经纪人'
						}
					}
				},
				Point:{
					width:80,
					items:{
						VPoint:{
							width:80,
							head:'上家点数'
						},
						BPoint:{
							width:80,
							head:'下家点数'
						}
					}
				},
                LoanDealMode: {
                    width: 80,
                    head: "贷款办理渠道"
                },
                SendDate: {
                    width: 80,
                    head: "发件日期"
                },
                ContractDate: {
                    width: 80,
                    head: "签约日期"
                },
                CertificationPserson: {
                    width: 120,
                    head: "办证人员"
                },
                DealDate: {
                    width: 80,
                    head: "预约过户日期"
                },
                ReciveDate: {
                    width: 80,
                    head: "收件收据日期"
                },
                ReciveCode: {
                    width: 120,
                    head: "收件收据编号",
                    textModel:true
                },
                AccptDate: {
                    width: 80,
                    head: "领证时间",
                    renderer:function(val,c,row){
						if(row.AccptInfo=="无领证时间#"){
							return "";
						}
						return val;
					}
                },
                LackInfo: {
                    width: 700,
                    head: "缺件内容"
                },
                PayStyle: {
                    width: 80,
                    head: "付款方式"
                }
            }
        });
    },
    loadInfo: function() {
        var _this = this;
        Chenxin.ajax({
            type: "get",
            dataType: "text",
            paramType: 'json',
            async: false,
            url: this.actionUrl,
            data: { op: 'getmodel', modelid: this.currentId },
            onSuccess: function(data, msg) {
                if (data) {
                    _this.currentInfo = data.model;
					_this.currentContractInfo = data.model1;
					
                }
            }
        });
    },
    loadCertificateInfo: function() {
        var _this = this;
        Chenxin.ajax({
            type: "get",
            dataType: "text",
            paramType: 'json',
            async: false,
            url: this.actionUrl,
            data: { op: 'getmodel1', modelid: this.currentId },
            onSuccess: function(data, msg) {
                if (data) {
                    _this.currentInfo = data.model;
					_this.currentCertificateInfo = data.model1;
					_this.currentContractInfo = data.model2;
                }
            }
        });
    },
    initEvent: function() {
        var _this = this;

        //底部按钮点击事件
        $('.LeftFooter a').click(function() {
            _this.bindBottomBar(this);
        });
    },
    bindBottomBar: function(obj) {
        switch (obj.name) {   
            //受理人输入         
            case "aSLInput":
                if (!this.currentId) {
                    alert('请选择一条成交记录！');
                    return;
                }
                this.slInput();
                break;
            //办证输入
			case "aBZInput":
                if (!this.currentId) {
                    alert('请选择一条成交记录！');
                    return;
                }
				this.loadCertificateInfo();
                this.addCertificateInput();
                break;
			//个案补证               
            case "aCaseDeal":
                if (!this.currentId) {
                    alert('请选择一条成交记录！');
                    return;
                }
				this.loadInfo();
                this.getLackItemsInfo();
                break;
            //合同详情
            case "aContractDetail":
                if (!this.currentId) {
                    alert('请选择一条成交记录！');
                    return;
                }
                  window.open("/page/Contract_ApplyInfo/ShowDetailContract.aspx?ContractId=" + this.currentId);
                break;
            default:
                alert("功能未开通");
        }
    },
    //受理输入
    slInput: function() {
        var _this = this;
        window.open("/page/Preliminary_Info/DealLoan.aspx?ContractId=" + _this.currentId+"");
    },
    //办证输入
    addCertificateInput: function() {
        if (!this.AddCertificateInfo) {
            this.AddCertificateInfo = new Chenxin.UI.AddCertificateInfo({
                scope: this,
                afterGetFormJson: function(json) {
				if(json.Finished=='undefine'){
					json.Finished = false;
                }
				//成交编号
				delete json.ContractCode;
				//成交日期
				delete json.ContractDate;
				//房屋合同价
				delete json.HousePrice;
				//合同标的
				delete json.BargainPrice;
				//建筑面积
				delete json.Area;
				//补偿款
				delete json.Compensate;
				//过户日期
				delete json.DealDate;
				//地址
				delete json.HouseAddress;
				json.ContractId = this.currentInfo.ContractId;				
                }
            });
        }
		var _data = {};
		Chenxin.apply(_data, this.currentInfo);
		if(this.currentCertificateInfo) {
			Chenxin.applyIf(_data, this.currentCertificateInfo);
		}
		if(this.currentContractInfo) {
			_data.HousePrice = this.currentContractInfo.HousePrice;
			_data.DealDate = this.currentContractInfo.DealDate;
			_data.Compensate = this.currentContractInfo.Compensate;
		}
        if (this.AddCertificateInfo.show(this.AddCertificateInfo.op)) {
			if(_data.SendDate)
			{
			    _data.SendDate=_data.SendDate.substring(0,10);
			}
			if(_data.DealDate)
			{
			    _data.DealDate =_data.DealDate.substring(0,10);
			}
			if(_data.PawnDate)
			{
			    _data.PawnDate =_data.PawnDate.substring(0,10);
			}
			if(_data.ReciveDate)
			{
			    _data.ReciveDate =_data.ReciveDate.substring(0,10);
			}
			if(_data.AccptDate)
			{
			    _data.AccptDate =_data.AccptDate.substring(0,10);
			}
			if(_data.AllSendDate)
			{
			    _data.AllSendDate =_data.AllSendDate.substring(0,10);
			}
			if(_data.GetAllSendDate)
			{
			    _data.GetAllSendDate =_data.GetAllSendDate.substring(0,10);
			}
			if(_data.ContractSendDate)
			{
			    _data.ContractSendDate =_data.ContractSendDate.substring(0,10);
			}
			if(_data.GetContractSendDate)
			{
			    _data.GetContractSendDate =_data.GetContractSendDate.substring(0,10);
			}
			if(_data.GetLandSendDate)
			{
			    _data.GetLandSendDate =_data.GetLandSendDate.substring(0,10);
			}
			if(_data.LandSendDate)
			{
			    _data.LandSendDate =_data.LandSendDate.substring(0,10);
			}
            if(_data.CertificationDpartId=="00000000-0000-0000-0000-000000000000")
            {
                _data.CertificationDpartId = null;
                _data.CertificationDpart = "请选择";
            }
            if(_data.CertificationPsersonId=="00000000-0000-0000-0000-000000000000")
            {
                _data.CertificationPsersonId = null;
                _data.CertificationPserson = "请选择";
            }
            if(_data.AccptInfo == "无领证时间#")
            {
                _data.AccptDate=null;
            }
            this.AddCertificateInfo.fitData(_data);
        }
    },
	//个案补证
    getLackItemsInfo: function() {
        var objPg = this;
        var json;
        if (this.addCertFrm == undefined) {
            this.addCertFrm = new Chenxin.UI.AddCertificatesFrm({
                scope: this,
                afterGetFormJson: function(json) {
                    if( json.IntentionCode ){
                        this.addCertFrm.additionalParam.IntentionCode = json.IntentionCode;
                    }
                    this.addCertFrm.additionalParam.ContractCode = json.ContractCode;
                    delete json.HouseAddress;
                    delete json.IntentionCode;
                    delete json.ContractCode;
                    json.ContractId = this.currentInfo.ContractId;
                }
            });
        }
		
        if (objPg.addCertFrm.show(objPg.addCertFrm.op, { CityId: objPg.currentInfo.BargainCityId, CompanyId: objPg.currentInfo.BargainCompanyId }) == true) {
            Chenxin.ajax({
                type: "get",
                dataType: "json",
                url: "/service/logic/ShowListBargain.ashx",
                data: { op: 'getlackitemsinfo', ContractId: this.currentId },
                onSuccess: function(data) {
                    var Contractdata = eval("({" + data + "})");
                    if (Contractdata.rows.length > 0) {
                        Contractdata = Contractdata.rows[0];
                    } else {
                        Contractdata = {};
                    }
                    Contractdata.ContractCode = objPg.currentInfo.ContractCode;
                    Contractdata.HouseAddress = objPg.currentInfo.HouseAddress;
                    objPg.addCertFrm.reset();
                    objPg.addCertFrm.fitData(Contractdata);
                }
            });
        }
    },
    initComponent: function() {
        Chenxin.UI.ShowListTransfer.superclass.initComponent.call(this);
    }
}); 

/**
*查询面板
*/
Chenxin.UI.ShowListTransferSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'transfer_search',
    initEvent: function() {
        var _this = this;
        
        //导出Excel
        $('#aExportExcel').click(function() {
            _this.exportData();
        });

        //查询按钮
        $('#btnSreach').click(function() {
            var data = _this.scope.search.getParamJson();
            _this.scope.searchGrid(data);
        });
        
        $('#KeyWord').defText({
            deftxt: '请输入地址或成交编号'
        });
        
        var curdate = new Date();
        $('#DateFr').val(curdate.getFullYear() + '-' + (curdate.getMonth() + 1) + '-1');
        if (curdate.getMonth() + 1 == 12)
            $('#DateTo').val(curdate.getFullYear() + 1 + '-1-1');
        else
            $('#DateTo').val(curdate.getFullYear() + '-' + (curdate.getMonth() + 2) + '-1');
    },
    createComboList: function() {
        //日期查询类型
        var ComboDateType = new Chenxin.UI.Combo({
            containerId: '#DateType',
            tbxWidth: 48,
            colWidth: 90,
            items: comboCommon.TransferDateType
        });
        //查询类型
        var ComboType = new Chenxin.UI.Combo({
            containerId: '#TransferType',
            tbxWidth: 48,
            colWidth: 70,
            items: comboCommon.TransferType
        });
        
        //查询类型
        var ComboRegion = new Chenxin.UI.Combo({
            containerId: '#Region',
            tbxWidth: 48,
            colWidth: 70,
            items: comboCommon.TransferRegion
        });
        
        //五级联Combo
        var combl = new Chenxin.UI.StructComboList();
        var structs = combl.comboList;
        structs.push(ComboDateType);
        structs.push(ComboType);
        structs.push(ComboRegion);
        return structs;
    },

    initComponent: function() {
        Chenxin.UI.ShowListTransferSearch.superclass.initComponent.call(this);
    }
});

/**
*办证输入
**/
Chenxin.UI.AddCertificateInfo = Chenxin.extend(Chenxin.UI.FormCommon, {
    id: "jqmCertificateForm",
    renderTo: 'jqmCertificate',
    actionUrl: "/service/logic/ShowListContract.ashx",
    title: "办证输入",
    op: "addcertificate",
    jqmWidth: 630,
    createForm: function() {
        return formCommon.CertificateInfoForm();
    },
    initFormValidator: function() {
        $("#LoanAmount").formValidator({
            validatorgroup: this.id,
            onshow: "请输入金额！",
            onfocus: " ",
            oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                return val.isNum();
            },
            onerror: "请输入数字！"
        });
    },
    createComboList: function() {
        var _this=this;
        //签约地点（部门）
        var CertificationDpartId = new Chenxin.UI.DepartTreeCombo({
            containerId: '#CertificationDpartId',
            textBoxId: 'CertificationDpartId',
            name: 'CertificationDpartId',
            inModelType: 'all',
            txtModelName: 'CertificationDpart',
            required: true,
            afterSetValue: function(val, txt) {
                if (val != this.defVal) {
                    CertificationPsersonId.loadUser(val)
                }
            },
            onSelected: function() {
                if (this.getValue() != this.defVal) {
                    CertificationPsersonId.loadUser(this.getValue());
                }
            }
        });
        
        //签约人
        var CertificationPsersonId = new Chenxin.UI.RichModelTreeCombo({
            containerId: '#CertificationPsersonId',
            textBoxId: 'CertificationPsersonId',
            inModelType: 'all',
            txtModelName: 'CertificationPserson',
            required: true,
            singleSelect: true,
            name: 'CertificationPsersonId'
        }); 
		return [CertificationPsersonId, CertificationDpartId];
    },
    initEvent: function() {
        var _this = this;
        $("#aSubmit1").click(function() {
			_this.op="addcertificate";
            _this.save();
        });
		$("#aClose1").click(function() {
            _this.hide();
        });
    },
    initComponent: function() {
        Chenxin.UI.AddCertificateInfo.superclass.initComponent.call(this);
    }
});

///**
//*个案补证
//**/
Chenxin.UI.AddCertificatesFrm = Chenxin.extend(Chenxin.UI.FormCommon, {
    id: "jqmAddCert",
    renderTo: 'jqmAddCert',
    actionUrl: "/service/logic/ShowListBargain.ashx",
    title: "个案补证",
    op: "deallackitems",
    defBBtn: false,
    autoHide:false,
    autoAlertSucc:false,
    createBBtn: function() {
        return [{text: '提交',handler: this.frmSubmit,scope: this},
                {text: '取消',handler: this.hide,scope: this}];
    },
    frmSubmit: function() {

        //资料一齐全时间判断
        if (this.comboList[0].getValue() == "false") {
            if ($("#txtCompleteDate1").val() == "") {
                alert("请输入资料一的齐全时间");
                return false;
            } else {
                var now = new Date();
                var inputDate = $("#txtCompleteDate1").val();
                var inputYear = parseInt(inputDate.substr(0, 4), 10);
                var inputMonth = parseInt(inputDate.substr(5, 2), 10);
                var inputDays = parseInt(inputDate.substr(8, 2), 10);
                if (inputYear == now.getFullYear() && (inputMonth - 1) == now.getMonth() && inputDays <= now.getDate()) {
                } else {
                    alert("请输入资料一的有效齐全时间");
                    return false;
                }
            }
        }
        //资料二齐全时间判断
        if (this.comboList[1].getValue() == "false") {
            if ($("#txtCompleteDate2").val() == "") {
                alert("请输入资料二的齐全时间");
                return false;
            } else {
                var now = new Date();
                var inputDate = $("#txtCompleteDate2").val();
                var inputYear = parseInt(inputDate.substr(0, 4),10);
                var inputMonth = parseInt(inputDate.substr(5, 2),10);
                var inputDays = parseInt(inputDate.substr(8, 2), 10);
                if (inputYear == now.getFullYear() && (inputMonth - 1) == now.getMonth() && inputDays <= now.getDate()) {
                } else {
                    alert("请输入资料二的有效齐全时间");
                    return false;
                }
            }
        }
        this.save();
    },
    beforeFitData: function(json) {
        //资料一齐全时间
        if (json.CompleteDate1 != undefined) {
            json.CompleteDate1 = json.CompleteDate1.split(" ")[0];
        }
        //资料二齐全时间
        if (json.CompleteDate2 != undefined) {
            json.CompleteDate2 = json.CompleteDate2.split(" ")[0];
        }
        //资料项目一
        if (json.IsLackItem1 != undefined) {
            json.IsLackItem1 = String(json.IsLackItem1);
        }
        //资料项目二
        if (json.IsLackItem2 != undefined) {
            json.IsLackItem2 = String(json.IsLackItem2);
        }
    },
    saveSucc: function(data, msg) {
        if (data == "Nodata") {
            alert(msg);
            $("#txtIntentionCode").focus();
            //已经关联
        } else if (data == "Exist") {
            alert(msg);
            $("#txtIntentionCode").focus();
        } else {
            alert(msg);
            this.addCertFrm.hide();
        }
        delete this.addCertFrm.additionalParam.IntentionCode;
        delete this.addCertFrm.additionalParam.ContractCode;
    },
    createForm: function() {
        return formCommon.AddCertificatesFrm(this.createLackItems1(), this.createLackItems2());
    },
    createLackItems1: function() {
        var strRet = "";
        var strLen = "140px";
        var jsonData = checkboxCommon.LackItems1;
        strRet = strRet + "<fieldset style='border:1px solid silver;margin: 0pt 0pt 10px;width:538px'>";
        strRet = strRet + "<ul>";
        for (var idxCnt = 0; idxCnt < jsonData.length; idxCnt++) {
            if (jsonData[idxCnt].txt.length > 10) {
                strLen = "260px";
            } else {
                strLen = "130px";
            }
            strRet = strRet + "<li style='display:inline;float:left;width:" + strLen + ";'>";
            strRet = strRet + '<input type="checkbox" name="LackItems1" value="' + jsonData[idxCnt].val + '" />' + jsonData[idxCnt].txt;
            strRet = strRet + "</li>";
        }
        strRet = strRet + "<li>";
        strRet = strRet + "<div style='display:block'><span class='fl'>其他</span><input name='LackOthers1' style='width:480px;margin:0 0 5px' type=text class='inputbox_n fl'/></div>";
        strRet = strRet + "</li>";
        strRet = strRet + "</ul>";
        strRet = strRet + "</fieldset>";
        return strRet;
    },
    createLackItems2: function() {
        var strRet = "";
        var jsonData = checkboxCommon.LackItems2;
        strRet = strRet + "<fieldset style='border:1px solid silver;width:538px'>";
        strRet = strRet + "<ul>";
        var strLen = "140px";
        for (var idxCnt = 0; idxCnt < jsonData.length; idxCnt++) {
            if (jsonData[idxCnt].txt.length > 10) {
                strLen = "260px";
            } else {
                strLen = "130px";
            }
            strRet = strRet + "<li style='display:inline;float:left;width:" + strLen + ";'>";
            strRet = strRet + '<input type="checkbox" name="LackItems2" value="' + jsonData[idxCnt].val + '" />' + jsonData[idxCnt].txt;
            strRet = strRet + "<li>";
        }
        strRet = strRet + "</ul>";
        strRet = strRet + "</fieldset>";
        return strRet;
    },
    createComboList: function() {
        //材料一齐全判断
        var cmbIsLackItem1 = new Chenxin.UI.Combo({
            containerId: '#IsLackItem1',
            name: 'IsLackItem1',
            required: true,
            tbxWidth: 120,
            colWidth: 80,
            items: comboCommon.IsLackItem,
            onSelected: function() {
                if (this._val == this.defVal) {
                    $("#txtCompleteDate1").attr("disabled", false);
                } else if (this._val == "true") {
                    $("#txtCompleteDate1").val("");
                    $("#txtCompleteDate1").attr("disabled", true);
                } else {
                    $("#txtCompleteDate1").attr("disabled", false);
                    $("input[name='LackItems1']").attr("checked", false);
                    $("input[name='LackOthers1']").val("");
                }
            },
            afterSetValue: function() {
                if (this._val == this.defVal) {
                    $("#txtCompleteDate1").attr("disabled", false);
                } else if (this._val == "true") {
                    $("#txtCompleteDate1").val("");
                    $("#txtCompleteDate1").attr("disabled", true);
                } else {
                    $("#txtCompleteDate1").attr("disabled", false);
                }
            }
        });
        //材料二齐全判断
        var cmbIsLackItem2 = new Chenxin.UI.Combo({
            containerId: '#IsLackItem2',
            name: 'IsLackItem2',
            required: true,
            tbxWidth: 120,
            colWidth: 80,
            items: comboCommon.IsLackItem,
            onSelected: function() {
                if (this._val == this.defVal) {
                    $("#txtCompleteDate2").attr("disabled", false);
                } else if (this._val == "true") {
                    $("#txtCompleteDate2").val("");
                    $("#txtCompleteDate2").attr("disabled", true);
                } else {
                    $("#txtCompleteDate2").attr("disabled", false);
                    $("input[name='LackItems2']").attr("checked", false);
                }
            },
            afterSetValue: function() {
                if (this._val == this.defVal) {
                    $("#txtCompleteDate2").attr("disabled", false);
                } else if (this._val == "true") {
                    $("#txtCompleteDate2").val("");
                    $("#txtCompleteDate2").attr("disabled", true);
                } else {
                    $("#txtCompleteDate2").attr("disabled", false);
                }
            }
        });
        return [cmbIsLackItem1, cmbIsLackItem2];
    },
    initEvent: function() {
        var objFrm = this;
        /*************事件：齐全时间1*************/
        $("#txtCompleteDate1").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
        $("#txtCompleteDate1").attr("disabled", true);
        /*************事件：齐全时间2*************/
        $("#txtCompleteDate2").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
        $("#txtCompleteDate2").attr("disabled", true);
        /*************事件：意向书编号检查*************/
        $("#txtIntentionCode").blur(function() {
            if ($(this).val() == "") {
                return false;
            }
            Chenxin.ajax({
                type: "get",
                dataType: "json",
                url: objFrm.actionUrl,
                data: { op: 'chkintentioncode', ContractId: objFrm.scope.currentId, IntentionCode: $(this).val() },
                onSuccess: function(data, msg) {
                    //不存在
                    if (data == "Nodata") {
                        alert(msg);
                        $("#txtIntentionCode").focus();
                        //已经关联
                    } else if (data == "Exist") {
                        alert(msg);
                        $("#txtIntentionCode").focus();
                    }
                }
            });
        });
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(document).ready(function(){
    this.ShowListTransfer=new Chenxin.UI.ShowListTransfer();
});